package uk.ac.cam.cl.android.jwdb;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;

public class LevelActivity extends Activity {
	
	int count;
	List<Level> levels;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_level);
		levels = getLevels();
		count = 0;
		nextLevel(0);
	}
	
	public void nextLevel(int score){
		if(count < levels.size()){
			Level level = levels.get(count);
			level.startLevel();
			count++;
			
		} else {
			gameOver(score);
		}
		
		initialiseListeners();
	}
	
	private void initialiseListeners() {
		ShakeListener shake = new ShakeListener(this.getApplicationContext());
		LiftListener lift = new LiftListener(this.getApplicationContext());
	}

	public void gameOver(int score) {
		Intent intent = new Intent(this,MainActivity.class);
		intent.putExtra("SCORE", score);
		startActivity(intent);
	}

	private List<Level> getLevels() {
		Button button = (Button) findViewById(R.id.button);
		TextView scoreText = (TextView) findViewById(R.id.score);
		scoreText.setText("0");
		TextView levelText = (TextView) findViewById(R.id.level);
		TextView timeText = (TextView) findViewById(R.id.time);

		Level level1 = new Level(10,button,1,scoreText,levelText,timeText,this);

		
		List<Level> levels = new ArrayList<Level>();
		levels.add(level1);
		return levels;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_level, menu);
		return true;
	}

	
}
